package controller;

import com.github.pagehelper.PageInfo;
import domain.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import service.LogService;

@Controller
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;

    @RequestMapping("/all")
    public ModelAndView all(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize,String username){
        ModelAndView modelAndView = new ModelAndView();
        System.out.println(username+"1");
        PageInfo<Log> logAll = logService.findLogAll(pageNum, pageSize,username);
        modelAndView.getModel().put("logs",logAll);
        modelAndView.setViewName("log_all");
        return modelAndView;
    }

    @RequestMapping("/desc")
    public ModelAndView desc(int id){
        ModelAndView modelAndView = new ModelAndView();
        Log log = logService.findLogById(id);
        modelAndView.getModel().put("log",log);
        modelAndView.setViewName("log_desc");
        return modelAndView;
    }
}
